package ia.test;

import ia.util.BytesToHex;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class ClientePrueba {

	/**cliente para probar funciones del server
	 * @param args
	 */
	public static void main(String[] args) {
		try{
			 Socket c = new Socket("localhost",1440);
			 BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
			    c.getOutputStream()));
			 BufferedReader r = new BufferedReader(new InputStreamReader(
			    c.getInputStream()));
			 
			 Thread.sleep(2000);
			 
			 //enviando "ejecutar aplicacion"
			 w.write(0x03);//Creo que es Longitud
			 w.write(0x00); 
			 w.write(0x00);//Creo que es Cabecera
			 w.flush();
			 
			 //recibiendo "leer sensor"
			 char[] recv = new char[6];
			 r.read(recv,0,6);
			 System.out.println(BytesToHex.convert(recv));
			 
			 Thread.sleep(5000);
			 //enviando lectura de sensor
			 w.write(0x13);
			 w.write(0x00); 
			 w.write(0x01);
			 for(int i = 0;i<16;i++)
				 w.write(0x01);
			 w.flush();
			 
			 
			 
			 Thread.sleep(400);
			 r.close();
			 w.close();
			 c.close();
			 c.close();
		}
		catch(Exception e){
			System.out.println("Excepcion");
		}

	}

	
}
